package com.coffee_shop_app.database.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "PcrDataManager.db";//数据库名字

    private static final int DATABASE_VERSION = 1; // 数据库的版本号

    public static final String CONTACTS_TABLE_NAME = "zksy_pcr_data"; //联系人表名

    //创建联系人表SQL语句
    public static final String CREATE_CONTACTS_TABLE =
            "create table " +
                    CONTACTS_TABLE_NAME +
                    "(" +
                    "id integer primary key autoincrement," +
                    "username varchar(128)," +
                    "serial_no varchar(128)," +
                    "link varchar(30) ," +
                    "status integer," +
                    "ip varchar(32)," +
                    "create_time varchar(13)," +
                    "channel text," +
                    "altitude REAL," +
                    "device_no varchar(128)," +
                    "kit_no varchar(128)," +
                    "temperature REAL," +
                    "humidity REAL," +
                    "pressure REAL," +
                    "longitude varchar(128)," +
                    "latitude varchar(128)," +
                    "fluid_ver varchar(10)," +
                    "result varchar(1)," +
                    "start_time BIGINT," +
                    "host_fw_ver varchar(128) ," +
                    "host_hw_ver varchar(128)," +
                    "client_hw_ver varchar(128)," +
                    "client_fw_ver varchar(128)," +
                    "pump_fw_ver varchar(128)," +
                    "valve_fw_ver varchar(128)," +
                    "chipname_c_n varchar(128)," +
                    "chipname_e_n varchar(128)," +
                    "custom varchar(20)," +
                    "host_fw_type varchar(128)," +
                    "result_show varchar(32)," +
                    "type varchar(2)," +
                    "remark varchar(100),"+
                    "sample_no varchar(128)" +
                    ")";
    /**
     * DatabaseHelper构造函数，传参数据库名，数据库版本，会自动创建数据库
     * @param context
     */
    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    /**
     * onCreate 回调SQLiteDatabase对象，自动执行创建表语句
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_CONTACTS_TABLE);
    }

    /**
     * 升级数据库。执行表结构变更语句
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//        if (newVersion > 1) {
//            //Android的ALTER命令不支持一次添加多列，只能分多次添加
//            String alter_sql = "ALTER TABLE " + CONTACTS_TABLE_NAME + " ADD COLUMN " + "phone_new2 VARCHAR;";
//            db.execSQL(alter_sql);
//            alter_sql = "ALTER TABLE " + CONTACTS_TABLE_NAME + " ADD COLUMN " + "phone_new3 VARCHAR;";
//            db.execSQL(alter_sql); // 执行完整的SQL语句
//        }
    }
}